Intro to Java
Create a new project - I recommend saving all these bluej files
in a bluej folder (on flash or h: drive) and name everything appropriate. Maybe create
a new project called IntroActivities
Applications
We are going to create a simple application. Use this as reference
for printing
out.
- Create a new class. Name it SimpleApp
- In the application code, delete
- all the methods but sampleMethod
- Update the comment in the beginning
- Make it say a bunch of different line
- Advanced - try to make it repeat
Applets
We are going to create a simple graphical applet.
- Create a new class and select applet. Name it SimpleDrawing
- In the applet code, delete
- all the methods but paint (there are 6 methods)
- the global variable x
- Update the comment in the beginning
- Make a simple drawing with atleast 4 different objects and colors.
Use the graphics
api for help.
User Interface
We are going to create a simple gui.
- Create a new applet. Name it SimpleGui
- In the applet code, in the init method add the code below:
Container con = getContentPane();
con.setBackground(Color.green);
con.setLayout (new FlowLayout() );
con.add(new JTextField(20));
con.add(new JButton ("Hit Me"));
- Update the comment in the beginning
- Try changing the color adding some new text fields and buttons and other items like below:
con.add(new JSlider(JSlider.HORIZONTAL,1,10,1)); //for a slider
con.add(new JTextArea(3,20)); //for a text area
con.add(new JProgressBar(1,10)); //for a progress bar
//FOR A MENU:
JMenuBar menuBar = new JMenuBar();
menuBar.add(new JMenu("A Menu"));
menuBar.add(new JMenu("Two"));
menuBar.add(new JMenu("Three"));
setJMenuBar(menuBar);
Heres a link to other components that you could use in your gui.
Stock quote:
Create 2 new classes called In and StockQuote -> copy the contents
from In and StockQuote
into your program.
Now lets use it.
3D Rotation
Create a new class (call it anything) and replace the code with this code and run.
|